﻿<UserControl x:Class="MissedMemo.MeatAndCheeseDisc.OrderEntry.viewOrderDetails"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:winforms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
    xmlns:local="clr-namespace:MissedMemo.MeatAndCheeseDisc.OrderEntry"
    Height="540" Width="400">

    <UserControl.Resources>
        <ResourceDictionary>

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="resOrderListItemStyles.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <DataTemplate x:Key="OrderItemTemplate">
                <DockPanel>
                    <Button Content="X" Foreground="Red" FontWeight="Bold" ToolTip="Delete Item" Click="btnX_Click" />
                    <TextBlock Margin="2,0,0,0" VerticalAlignment="Center" Text="{Binding Type}" />
				</DockPanel >
            </DataTemplate>

            <Style x:Key="RoundedOrderItemListBorderStyle" TargetType="Border" >
                <Setter Property="Background" Value="{x:Null}" />
                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" />
                <Setter Property="BorderThickness" Value="1" />
                <Setter Property="CornerRadius" Value="6" />
                <Setter Property="Padding" Value="3" />
                <Setter Property="Margin" Value="0,8" />
            </Style>

            <local:WinFormsControlVisibilityConverter x:Key="WinFormsControlVisibilityConverter" />
            <local:GridColumnWidthConverter x:Key="GridColumnWidthConverter" />
            <local:OrderStateToCheckStateConverter x:Key="OrderStateToCheckStateConverter" />
            <local:OrderStateToCheckEnabledConverter x:Key="OrderStateToCheckEnabledConverter" />

        </ResourceDictionary>
    </UserControl.Resources>

    
    <Grid Margin="12">

        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>

        
        <GroupBox Grid.Row="0" Margin="0,0,0,5" Header="Add Pizza"
                  BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}">
            <Grid>

                <Grid.Resources>
                    <Style TargetType="ComboBox">
                        <Setter Property="SelectedIndex" Value="0" />
                        <Setter Property="Margin" Value="3" />
                        <Setter Property="Background" Value="Transparent" />
                    </Style>
                </Grid.Resources>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition Width="auto" />
                </Grid.ColumnDefinitions>

                <ComboBox Grid.Column="0" Name="comboPizzaType" />
                <ComboBox Grid.Column="1" Name="comboPizzaSize" />
                <Button Grid.Column="2" Padding="5,2" Margin="3" Content="Add" Click="btnAddItem_Click" />

            </Grid>            
        </GroupBox>

        
        <Border Grid.Row="1" Style="{StaticResource RoundedOrderItemListBorderStyle}">
            <ListView Name="listOrderItems" ItemsSource="{Binding Items}" Background="{x:Null}" BorderThickness="0" >
                <ListView.View>
                    <GridView >
                        
                        <!-- There is currently no built-in support for AUTOMATIC column sizing, so we must calculate... -->
                        <GridViewColumn Header="Item" CellTemplate="{StaticResource OrderItemTemplate}"
                                        Width="{Binding ActualWidth, ElementName=listOrderItems,
                                        Converter = {StaticResource GridColumnWidthConverter}, ConverterParameter=0.50}" />
                        <GridViewColumn Header="Size" DisplayMemberBinding="{Binding Size}"
                                        Width="{Binding ActualWidth, ElementName=listOrderItems,
                                        Converter = {StaticResource GridColumnWidthConverter}, ConverterParameter=0.30}" />
                        <GridViewColumn Header="Price" DisplayMemberBinding="{Binding Price,
                                        Converter={StaticResource FormattedTextConverter}, ConverterParameter='{}{0:C2}'}"
                                        Width="{Binding ActualWidth, ElementName=listOrderItems,
                                        Converter = {StaticResource GridColumnWidthConverter}, ConverterParameter=0.20}" />
                    </GridView>
                </ListView.View>
            </ListView>
        </Border>


        <Grid Grid.Row="2" Margin="10">

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="20" />
                <RowDefinition Height="20" />
                <RowDefinition Height="30" />
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0" Grid.Column="0" Text="Ordered:" />
            <TextBlock Grid.Row="0" Grid.Column="1" Margin="8,0,0,0"
                       Text="{Binding DateTimeOrderPlaced, Converter={StaticResource FormattedTextConverter},
                       ConverterParameter='{}{0:M/d/yy  h:mm tt}'}" />
            
            <TextBlock Grid.Row="1" Grid.Column="0" Text="Expected:" />
            
            <!-- Show/hide WinForms control during animation of WPF container -->
            
            <WindowsFormsHost Grid.Row="1" Grid.Column="1" Margin="8,0,0,0"
             Visibility="{Binding ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl},
                Converter={StaticResource WinFormsControlVisibilityConverter}}" >
                <winforms:DateTimePicker x:Name="datepickerOrderExpected" Width="140" Format="Custom"
                 CustomFormat="M/dd/yy  h:mm tt" ValueChanged="OnEditDateTimeOrderExpected" />
            </WindowsFormsHost>
            
            <CheckBox Grid.Row="5" Grid.Column="0" VerticalAlignment="Center" Content="Done:"
                      IsChecked="{Binding ProcessingState, Converter={StaticResource OrderStateToCheckStateConverter}}"
                      IsEnabled="{Binding ProcessingState, Converter={StaticResource OrderStateToCheckEnabledConverter}}" />
            <TextBlock Grid.Row="5" Grid.Column="1" VerticalAlignment="Center" Margin="8,0"
                       Text="{Binding DateTimeOrderCompleted, Converter={StaticResource FormattedTextConverter},
                       ConverterParameter='{}{0:M/d/yy  h:mm tt}'}" />
            
            <TextBlock Name="txtSubTotal" Grid.Row="0" Grid.Column="3" Text="SubTotal:" />
            <TextBlock Grid.Row="0" Grid.Column="4"
                       Text="{Binding CostPreTax, Converter={StaticResource FormattedTextConverter},
                       ConverterParameter='{}{0,8:C2}'}" />
		    
            <TextBlock Grid.Row="1" Grid.Column="3" Text="Local Tax:" />
            <TextBlock Grid.Row="1" Grid.Column="4" 
                       Text="{Binding Tax, Converter={StaticResource FormattedTextConverter},
                       ConverterParameter='{}{0,8:C2}'}" />
            
            <Line Grid.Row="2" Grid.Column="3" Grid.ColumnSpan="2" Stroke="{Binding Foreground, ElementName=txtSubTotal}" X2="120" />
            <TextBlock Grid.Row="2" Grid.Column="4" FontWeight="Bold"
                       Text="{Binding TotalCost, Converter={StaticResource FormattedTextConverter},
                       ConverterParameter='{}{0,8:C2}'}" />

        </Grid>

    </Grid>
    
</UserControl>
